<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>侦听器的基本使用</title>
</head>
<body>
<div id="app">
    <!--  当变量内容发生变化的时候，计算属性无法确定是哪一个变量引起的变化  -->
    <div>
        姓氏：
        <input type="text" id="familyName" name="familyName" v-bind:value="familyName" v-on:input="onFamilyNameChange">
    </div>

    <div>
        名字：
        <input type="text" id="firstName" name="firstName" v-bind:value="firstName" v-on:input="onFirstNameChange">
    </div>

    <!--    <div>姓名：{{  familyName + " " + firstName }}</div>-->
    <div>姓名：{{ fullName }}</div>
</div>

<script src="../../../../../js/vue.global.js"></script>
<script>
    const app = Vue.createApp({
        data() {
            return {
                familyName: null,
                firstName: null,

                fullName: null,
            }
        },
        methods: {
            onFamilyNameChange() {
                let element = document.getElementById("familyName")
                this.familyName = element.value
                console.log(this.familyName);
            },
            onFirstNameChange() {
                let element = document.getElementById("firstName")
                this.firstName = element.value
                console.log(this.firstName);
            }
        },
        // computed: {
        //     fullName() {
        //         return this.familyName + " " + this.firstName
        //     }
        // }

        watch: {
            familyName(value) {
                console.log("变量 familyName 的值发生了变化");
                this.fullName = value + " " + this.firstName
            },
            firstName(value) {
                console.log("变量 firstName 的值发生了变化");
                this.fullName = this.familyName + " " + value
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>